package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.service.DtsGoodsproductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/10/13 20:49
 */
@Service
public class DtsGoodsproductServiceImpl implements DtsGoodsproductService {

    @Autowired
    DtsGoodsProductMapper productMapper;


    @Override
    public long getTotal() {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getDeleted,false);

        Integer count = productMapper.selectCount(wrapper);
        return count;

    }

    @Override
    public void insert(DtsGoodsProduct product) {
        product.setAddTime(new Date());
        product.setUpdateTime(new Date());
        product.setDeleted(false);

        productMapper.insert(product);
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsProduct::getGoodsId,id);
        productMapper.delete(wrapper);
    }
}
